﻿var acceptClick;
var keyValue = '';
var bootstrap = function ($, learun) {
    "use strict";
    var selectedRow = config.getParent(learun).selectedRow;
    var ue;
    var page = {
        init: function () {
            page.bind();
            page.initData();
        },
        bind: function () {
            //公告类别
            $('#category').lrDataItemSelect({code: 'NoticeCategory', maxHeight: 230});
            //内容编辑器
            ue = UE.getEditor('editor');
        },
        initData: function () {
            if (!!selectedRow) {
                keyValue = selectedRow.id;
                $('#form').lrSetFormData(selectedRow);
                $("#publicTime").val(learun.formatDate(selectedRow.publicTime, 'yyyy-MM-dd hh:mm'));
                $.lrSetForm(config.base_server() + 'notices/findById?keyValue=' + keyValue, function (data) {
                    setTimeout(function () {
                        ue.setContent(data.content);
                    }, 100);
                });
            }
        }
    };
    acceptClick = function (callBack) {
        if (!$('#form').lrValidform()) {
            return false;
        }
        var postData = $('#form').lrGetFormData(keyValue);
        postData["content"] = ue.getContent(null, null, true);
        $.lrSaveForm(config.base_server() + 'notices/saveOrUpdate?access_token=' + config.getToken().access_token + '&keyValue=' + keyValue, JSON.stringify(postData), function (res) {
            // 保存成功后才回调
            if (!!callBack) {
                callBack();
            }
        });
    }

    page.init();
}


